package com.config;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;
@Configuration
public class LocaleConfig implements LocaleResolver{

	public Locale resolveLocale(HttpServletRequest request) {
		String L=request.getParameter("L");
        if(!StringUtils.isEmpty(L)) {
            String [] part=L.split("_");
            //	Locale locale=new Locale("zh", "CN");
            Locale locale=new Locale(part[0],part[1]);
            return locale;
        }
        else {
            return Locale.getDefault();
        }	
	}

	@Override
	public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
		// TODO Auto-generated method stub
		
	}
	@Bean
	LocaleResolver localeResolver() {
		return this;
	}
}
